//
//  SerialCell.m
//  aiteshangcheng
//
//  Created by caominglei on 2018/4/24.
//  Copyright © 2018年 aite. All rights reserved.
//

#import "SerialCell.h"
#import "NSString+time.h"
#import "UIImage+Category.h"
#import "YCCommonCtrl.h"
#import "Masonry.h"
@implementation SerialCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setModel:(SerialModel *)model
{
    _model = model;
    
    self.orderLabel.text = model.pdr_sn;
    self.timeLabel.text = [NSString ConvertStrToTime:model.pdr_sn];
    self.amountLabel.text = [NSString stringWithFormat:@"+%@",model.pdr_amount];
    if ([model.pdr_payment_state integerValue] == 0) {
        self.stateLabel.text = @"未支付";
    }else{
        self.stateLabel.text = @"已支付";
    }
    [self.paybtn setTitle:@"支付" forState:UIControlStateNormal];
    [self.deletebtn setTitle:@"删除" forState:UIControlStateNormal];

}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpSubviews];
        [self createSubviewsFrame];
    }
    return self;
}

- (void)setUpSubviews
{
    UILabel *orderLabel = [YCCommonCtrl commonLableWithFrame:CGRectZero text:@"" color:[UIColor blackColor] font:[UIFont systemFontOfSize:10] textAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:orderLabel];
    orderLabel.numberOfLines = 0;
    self.orderLabel = orderLabel;
    
    UILabel *timeLabel = [YCCommonCtrl commonLableWithFrame:CGRectZero text:@"" color:[UIColor blackColor] font:[UIFont systemFontOfSize:10] textAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:timeLabel];
    timeLabel.numberOfLines = 0;
    self.timeLabel = timeLabel;
    
    UILabel *amountLabel = [YCCommonCtrl commonLableWithFrame:CGRectZero text:@"" color:[UIColor blackColor] font:[UIFont systemFontOfSize:10] textAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:amountLabel];
    amountLabel.numberOfLines = 0;
    amountLabel.textColor = [UIColor redColor];
    self.amountLabel = amountLabel;
    
    UILabel *stateLabel = [YCCommonCtrl commonLableWithFrame:CGRectZero text:@"" color:[UIColor blackColor] font:[UIFont systemFontOfSize:10] textAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:stateLabel];
    stateLabel.numberOfLines = 0;
    self.stateLabel = stateLabel;
    
    UIButton *paybtn = [YCCommonCtrl commonButtonWithFrame:CGRectZero title:@"支付" color:[UIColor grayColor] font:[UIFont systemFontOfSize:10] backgroundImage:[UIImage createImageWithColor:[UIColor clearColor]] target:self action:@selector(pay:)];
    paybtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:paybtn];
    self.paybtn = paybtn;
    
    UIButton *deletebtn = [YCCommonCtrl commonButtonWithFrame:CGRectZero title:@"删除" color:[UIColor grayColor] font:[UIFont systemFontOfSize:10] backgroundImage:[UIImage createImageWithColor:[UIColor clearColor]] target:self action:@selector(delete:)];
    deletebtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:deletebtn];
    self.deletebtn = deletebtn;

}


- (void)pay:(UIButton *)btn
{
    if ([self.delegate respondsToSelector:@selector(payOrder)]) {
        [self.delegate payOrder];
    }
}

- (void)delete:(UIButton *)delete
{
    if ([self.delegate respondsToSelector:@selector(deleteOrder)]) {
        [self.delegate deleteOrder];
    }
}
- (void)createSubviewsFrame
{
    [self.orderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(80);
        make.width.mas_equalTo(50);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.orderLabel.mas_right).offset(5);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(80);
        make.width.mas_equalTo(80);
    }];
    
    [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.timeLabel.mas_right).offset(10);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(80);
        make.width.mas_equalTo(80);
    }];
    
    [self.stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.amountLabel.mas_right).offset(5);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(80);
        make.width.mas_equalTo(40);
    }];
    
    [self.paybtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(50);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(40);
        make.right.mas_equalTo(-5);
    }];
    
    [self.deletebtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(50);
        make.bottom.mas_equalTo(-5);
        make.height.mas_equalTo(40);
        make.right.mas_equalTo(-5);
    }];
}
@end
